import { getAreaInfo } from '@/api/area'
export const getCurrentCity = () => {
  const localCity = JSON.parse(localStorage.getItem('hkzf_city'))
  if (!localCity) {
    return new Promise((resolve, reject) => {
      try {
        const myCity = new window.BMapGL.LocalCity()
        // console.log('mycity', myCity)
        myCity.get(async res => {
          const cityName = res.name
          console.log('当前定位城市名称为：', cityName)
          const { data: areares } = await getAreaInfo(cityName)
          // 4.2 获取到结果只会，并且存储到本地存储中
          localStorage.setItem('hkzf_city', JSON.stringify(areares.body))
          // 4.3 返回该城市数据
          resolve(areares.body)
        })
      } catch (error) {
        console.log('进入错误了', error)
        reject(error)
      }
    })
  }
  return Promise.resolve(localCity)
}
